//
//  XYShareView.m
//  NemoSDKDemo
//
//  Created by 高超 on 2020/8/7.
//  Copyright © 2020 JackYang. All rights reserved.
//

#import "XYShareView.h"

@interface XYShareView ()

@property (nonatomic, strong) UIImageView *bgImgView;

@property (nonatomic, strong) UIImageView *phoneImgView;

@end

@implementation XYShareView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self _setupUI];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChange) name:UIApplicationDidChangeStatusBarOrientationNotification
                                                   object:nil];
    }
    return self;
}

-(void)_setupUI {
    self.userInteractionEnabled = NO;
    self.backgroundColor = [UIColor blackColor];
    self.bgImgView = [[UIImageView alloc] initWithFrame:self.bounds];
    self.bgImgView.contentMode = UIViewContentModeScaleAspectFit;
    [self addSubview:self.bgImgView];
    
    self.phoneImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 120, 120)];
    self.phoneImgView.center = self.center;
    self.phoneImgView.contentMode = UIViewContentModeScaleAspectFit;
    self.phoneImgView.image = [UIImage imageNamed:@"broadcast_placeholder"];
    [self addSubview:self.phoneImgView];
}

- (void)setType:(XYShareViewType)type {
    _type = type;
    if (type == XYShareViewTypeScreen) {
        self.bgImgView.image = [UIImage imageNamed:@"onhold_normal_bg"];
        self.bgImgView.contentMode = UIViewContentModeScaleAspectFill;
    }else {
        self.phoneImgView.hidden = YES;
    }
}

- (void)setImage:(UIImage *)image {
    if (!image) {
        image = [UIImage imageNamed:@"Logo"];
    }
    self.bgImgView.image = image;
}

- (void)orientationChange {
    self.frame = CGRectMake(0, 0, kScreen.width, kScreen.height);
    self.bgImgView.frame = self.bounds;
    self.phoneImgView.center = self.center;
}

@end
